package _nio._socket._bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: huangya
 * @Date: 2020/5/29
 * @Description:
 * todo: println() & print()
 */
public class TimeServer {

    public static void main(String[] args) {
        int port = 8080;
        if(args!=null && args.length>0){
            try {
                port = Integer.parseInt(args[0]);
            }catch (Exception e){

            }
        }

        ServerSocket server = null;
        try {
            server = new ServerSocket(port);
            Socket socket;
            while(true){
                socket = server.accept();
                new Thread(new TimeServerHandle(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(server!=null){
                try {
                    server.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                server=null;
            }
        }
    }
}
